<div class="layuimini-container layuimini-page-anim">
    <div class="layuimini-main">

        <table class="layui-hide" id="role-table-page" lay-filter="currentTableFilter"></table>
        <script type="text/html" id="currentTableFilter">
            <{if AdminUsersModel::check_right("$module/$controller/save")}>
            <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
            <{/if}>
            <{if AdminUsersModel::check_right("$module/$controller/del")}>
            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
            <{/if}>
            <{if AdminUsersModel::check_right("$module/$controller/killuser")}>
            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="logout">踢下线</a>
            <{/if}>
            <{if AdminUsersModel::check_right("$module/$controller/resetgg")}>
            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="refreshgg">重置二次验证码</a>
            <{/if}>
        </script>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <{if AdminUsersModel::check_right("$module/$controller/save")}>
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add">添加</button>
                <{/if}>
            </div>
        </script>

        <script type="text/html" id="userlist-status-btn">
            {{#  if(d.status == 1){ }}
            <button class="layui-btn layui-btn-xs">正常</button>
            {{#  } else { }}
            <button class="layui-btn layui-btn-primary layui-btn-xs">禁用</button>
            {{#  } }}
        </script>
    </div>
</div>

<script type="text/javascript">
    layui.use(['form', 'table', 'miniPage', 'element'], function () {
        var table = layui.table;
        var miniPage = layui.miniPage;
        table.render({
            elem: '#role-table-page'
            , toolbar: '#toolbarDemo'
            , defaultToolbar: ['filter', 'exports']
            , url: '/<{$module}>/<{$controller}>/index?do=list&isajax=1'
            , limit: 30
            , height: 'full-150'//一行条件
            , cols: [[
                {field: 'id', width: 80, title: 'ID', sort: true}
                , {field: 'username', title: '用户名', width: 180}
                , {field: 'group_name', title: '角色组', width: 180}
                , {field: "status", title: "状态", templet: "#userlist-status-btn", width: 80, align: "center"}
                , {align: 'left', fixed: 'right', toolbar: '#currentTableFilter'}
            ]]
            , page: true
        });

        var $ = layui.$, active = {
            edit: function (obj) { //获取选中数据
                var data = obj.data;
                var content = miniPage.getHrefContent('/<{$module}>/<{$controller}>/save/id/' + data.id);
                var index = layer.open({
                    type: 1
                    , title: '编辑'
                    , content: content
                    , maxmin: true
                    , area: ['60%', '90%']
                    , btn: ['确定', '取消']
                    , yes: function (index, layero) {
                        //点击确认触发 iframe 内容中的按钮提交
                        layero.find("#form-submit").click();
                    }
                });
            }
            , del: function (obj) {
                var data = obj.data;
                var index = layer.confirm('确定需要删除吗?', function (index) {
                    $.post('/<{$module}>/<{$controller}>/del/id/' + data.id + '?isajax=1', {}, function (res) {
                        layer.msg(res.msg);
                    }, 'json');
                    table.reload('role-table-page');
                    layer.close(index);
                });
            }
            , logout: function (obj) {
                // T出去
                var data = obj.data;
                var index = layer.confirm('点击确定可以T出账户,使其强制下线?', function (index) {
                    $.post('/<{$module}>/<{$controller}>/killuser/id/' + data.id + '?isajax=1', {}, function (res) {
                        layer.msg(res.msg);
                    }, 'json');
                    table.reload('role-table-page');
                    layer.close(index);
                });
            }
            , refreshgg: function (obj) {
                // T出去
                var data = obj.data;
                var index = layer.confirm('点击确定可以重置Google二次验证码!', function (index) {
                    $.post('/<{$module}>/<{$controller}>/resetgg/id/' + data.id + '?isajax=1', {}, function (res) {
                        layer.msg(res.msg);
                    }, 'json');
                    table.reload('role-table-page');
                    layer.close(index);
                });
            }
            , add: function () {
                var content = miniPage.getHrefContent('/<{$module}>/<{$controller}>/save');
                var index = layer.open({
                    title: '添加'
                    , type: 1
                    , shade: 0.5
                    , maxmin: true
                    , area: ['60%', '90%']
                    , shadeClose: true
                    , content: content
                    , btn: ['确定', '取消']
                    , yes: function (index, layero) {
                        layero.find("#form-submit").click();
                    }
                });
            }

        };
        //监听工具条
        table.on('tool(currentTableFilter)', function (obj) {
            var type = obj.event;
            active[type] ? active[type].call(this, obj) : '';
        });
        table.on('toolbar(currentTableFilter)', function (obj) {
            var type = obj.event;
            active[type] ? active[type].call(this, obj) : '';
        });
    });
</script>